<?php
Core::getInstance()->app_load_class('Admin',false);
Core::getInstance()->sys_load_class('Character',false);
Core::getInstance()->sys_load_class('Model',false);
Core::getInstance()->app_load_class('FileSystem',false);
class Attachment extends Admin{
	/*Singleton{{{*/
	public static function getInstance(){
		static $instance=null;
		if($instance===null){ 
			$instance = new self();
		}
		return $instance;
	}
	private function __construct(){}
	private function __clone(){
		trigger_error("Clone is not allowed.", E_USER_ERROR);
	}
	/*}}}*/

	public function uploadAction(){
		$title= '图片上传';
		if(!empty($_FILES)){
			$file = new FileSystem();
			$r=$file->upload();
			if($r){
				Core::sucmessage('Upload is successful!');
				header('Location:?m=admin&c=attachment&a=list');
			}else{
				Core::showmessage('It is failure that file upload!');
			}
		}
		include $this->display('attachment_upload.tpl.php');
	}

	public function listAction(){
		$title='附件管理';
		$file = new FileSystem();
		$data = $file->lists();
		include $this->display('attachment_list.tpl.php');
	}

	public function delAction(){
		if(!isset($_GET['id'])){
			Core::showmessage('Invalid Operate');
		}

		$id = intval($_GET['id']);

		$file = new FileSystem();
		$file->delData($id);

		header('Location:?m=admin&c=attachment&a=list');
	}
}
